package login

import (
	"context"
	v1 "donkey-admin/api/taskLog/v1"
	"donkey-admin/internal/dao"
	"donkey-admin/internal/model/entity"
	"github.com/gogf/gf/v2/errors/gerror"
	"github.com/gogf/gf/v2/frame/g"
)

func (s *sTaskLog) FindSysTaskLog(ctx context.Context, req *v1.FindSysTaskLogReq) (res *v1.FindSysTaskLogRes, err error) {

	var logList []entity.SysTaskLog
	count := 0
	err = dao.SysTaskLog.Ctx(ctx).Where("task_id", req.Uuid).Page(req.Page, req.PageSize).ScanAndCount(&logList, &count, true)
	if err != nil {

		g.Log().Error(ctx, err)
		return nil, gerror.New("创建失败")
	}

	return &v1.FindSysTaskLogRes{
		Rows:     logList,
		Page:     req.Page,
		PageSize: req.PageSize,
		Total:    count,
	}, nil
}
